package servlet;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * @author 石小俊
 * @date 2023年10月20日 16:08
 */
//@WebServlet(urlPatterns = "/life",loadOnStartup = 1)
public class LifeServlet implements Servlet {

    private ServletConfig config;

    @Override
    public void init(ServletConfig config) throws ServletException {
        System.out.println("*******************初始化*******************");
        String encoding = config.getInitParameter("encoding");
        String name = config.getInitParameter("name");
        System.out.println("encoding:"+encoding+",name:"+name);
        this.config = config;
    }

    @Override
    public ServletConfig getServletConfig() {
        return config;
    }

    public String getInitParameter(String key){
        return getServletConfig().getInitParameter(key);
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("*******************执行核心业务逻辑*******************");
        String encoding = getInitParameter("encoding");
        String name = getInitParameter("name");
        System.out.println("encoding:"+encoding+",name:"+name);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {
        System.out.println("*******************销毁*******************");
    }
}
